package com.qidian.tcba.admin.api.controller;


import com.qidian.tcba.admin.model.dto.district.DistrictListDTO;
import com.qidian.tcba.admin.service.UserDistrictService;
import com.qidian.tcba.utils.result.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户区县表 前端控制器
 * </p>
 *
 * @author 冯永龙
 * @since 2021-07-06
 */
@RestController
@RequestMapping("/userDistrict")
@Api(tags ="用户区县")
public class UserDistrictController {

    @Autowired
    private UserDistrictService userDistrictService;

    @ApiOperation("获取用户区县列表")
    @GetMapping("/getUserDistrictList/{userId}")
    public JsonResult getUserDistrictList(@PathVariable("userId")int userId){
        List<DistrictListDTO> userDistrictList = userDistrictService.getUserDistrictList(userId);
        return JsonResult.success().data("rows",userDistrictList);
    }

    @PostMapping("/deleteDistrict/{userId}")
    public JsonResult deleteDistrict(@PathVariable int userId,@RequestBody List<Integer> districtIds){
        boolean res = userDistrictService.deleteUserDistrictList(userId, districtIds);
        if (res){
            return JsonResult.success();
        }else {
            return JsonResult.error();
        }
    }
}

